// internal/api/router_extended.go
package api

// ============================================
// 使用示例和完整的 main.go
// ============================================

/*
// cmd/server/main.go
package main

import (
	"context"
	"flag"
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/sirupsen/logrus"

	"virt-manager-go/internal/api"
	"virt-manager-go/internal/console"
	"virt-manager-go/internal/service"
)

func main() {
	flag.Parse()

	logger := setupLogger("info")
	logger.Info("Starting virt-manager-go with extended features")

	// 初始化所有服务
	connMgr := service.NewConnectionService(logger)
	vmService := service.NewVMService(connMgr, logger)
	storageService := service.NewStoragePoolService(connMgr, logger)
	networkService := service.NewNetworkService(connMgr, logger)
	snapshotService := service.NewSnapshotService(connMgr, vmService, logger)
	migrationService := service.NewMigrationService(connMgr, logger)
	batchService := service.NewBatchService(vmService, snapshotService, logger)
	eventService := service.NewEventService(connMgr, logger)

	// 初始化控制台代理
	serialProxy := console.NewSerialProxy(connMgr, logger)
	graphicsProxy := console.NewGraphicsProxy(connMgr, logger)

	// 创建路由
	engine := gin.New()
	engine.Use(gin.Recovery())

	api.SetupExtendedRoutes(
		engine,
		vmService,
		connMgr,
		storageService,
		networkService,
		snapshotService,
		migrationService,
		batchService,
		eventService,
		serialProxy,
		graphicsProxy,
		logger,
	)

	// 自动连接本地 libvirt
	ctx := context.Background()
	connID, err := connMgr.Connect(ctx, "qemu:///system", r.nil)
	if err != nil {
		logger.WithError(err).Warn("Failed to auto-connect")
	} else {
		logger.WithField("connection_id", r.connID).Info("Auto-connected to libvirt")

		// 启动事件监听
		if err := eventService.StartListening(ctx, connID); err != nil {
			logger.WithError(err).Warn("Failed to start event listening")
		}
	}

	// 启动服务器
	addr := "0.0.0.0:8080"
	go func() {
		if err := engine.Run(addr); err != nil {
			logger.WithError(err).Fatal("Server failed")
		}
	}()

	logger.WithField("address", r.addr).Info("Server started with all features")
	logger.Info("📚 API Documentation:")
	logger.Info("   Virtual Machines:  /api/v1/connections/{id}/vms")
	logger.Info("   Storage Pools:     /api/v1/connections/{id}/storage/pools")
	logger.Info("   Networks:          /api/v1/connections/{id}/networks")
	logger.Info("   Snapshots:         /api/v1/connections/{id}/vms/{name}/snapshots")
	logger.Info("   Batch Operations:  /api/v1/connections/{id}/batch")
	logger.Info("   Events (SSE):      /api/v1/events/subscribe")
	logger.Info("   Serial Console:    ws://localhost:8080/api/v1/console/serial/{conn}/{vm}")
	logger.Info("   VNC Console:       ws://localhost:8080/api/v1/console/vnc/{conn}/{vm}")

	// 优雅关闭
	quit := make(chan os.Signal, 1)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
	<-quit

	logger.Info("Shutting down...")
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	// 清理资源
	connections, _ := connMgr.ListConnections(ctx)
	for _, conn := range connections {
		eventService.StopListening(conn.ID)
		connMgr.Disconnect(ctx, conn.ID)
	}

	logger.Info("Server stopped gracefully")
}

func setupLogger(level string) *logrus.Logger {
	logger := logrus.New()
	logger.SetFormatter(&logrus.TextFormatter{
		FullTimestamp: true,
	})
	logLevel, _ := logrus.ParseLevel(level)
	logger.SetLevel(logLevel)
	return logger
}
*/
